import Controller from "./Controller";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Main extends cc.Component {

    @property(cc.Prefab)
    rect: cc.Prefab = null;

    onLoad() {
        Controller.initTree(cc.winSize.width, cc.winSize.height);
        this.createNodes();
    }

    private createNodes() {
        const w = cc.winSize.width;
        const h = cc.winSize.height;

        for (let index = 0; index < 2000; index++) {
            const x = Math.random() * w - w / 2;
            const y = Math.random() * h - h / 2;

            this.createNode(x, y);
        }
    }

    private createNode(x: number, y: number) {
        const node = cc.instantiate(this.rect);
        node.parent = this.node;
        node.x = x;
        node.y = y;
    }
}
